package com.maq.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.maq.domain.vo.BoyBase;
import com.maq.domain.vo.GirlBase;
import com.maq.domain.vo.supper.PeopleBase;
import com.maq.persistence.PeopleBaseDao;

@Service
@Transactional
public class PeopleBaseService {
	@Autowired
	private PeopleBaseDao peopleBaseDao;

	public PeopleBase findByEmailOrPhone(PeopleBase peopleBase) {
		// 用户登录时的input名为Email但 输入可能是phone
		// 因此如果不是Email先修正为phone
		String tempString = peopleBase.getEmail();

		return peopleBaseDao.findPeopleByEmailOrPhone(tempString);
	}

	public void save(PeopleBase peopleBase) {
		String strTemp = peopleBase.getEmail();
		if (strTemp.contains("@")) {
			
		} else {
			peopleBase.setPhone(strTemp);
			peopleBase.setEmail("");
		}
		if (peopleBase.getGender() == 1) {
			peopleBaseDao.saveOrUpdate((BoyBase) peopleBase);
		} else {
			peopleBaseDao.saveOrUpdate((GirlBase) peopleBase);
		}
	}

}
